﻿<meta http-equiv="content-type" content="text/html; charset=utf-8">
页面代码
<script  src="http://www.bhu.ac.cn/js/jquery.1.8.3.js"></script>
<?php
$json_string = file_get_contents("1.json");// 从文件中读取数据到PHP变量
$data = json_decode($json_string,true);// 把JSON字符串转成PHP数组
?>
<div style="width: 102px; height: auto; overflow: hidden; margin:0 auto;">
	<input id="name" style="width: 100px; height: 25px; border: #ccc 1px solid;" value="<?=$data["data"]["name"]?>">
	<input id="age" style="width: 100px; height: 25px; border: #ccc 1px solid;" value="<?=$data["data"]["age"]?>">
	<button id="submit">提交</button>
</div>
<script type="text/javascript">
var btn = document.getElementById("submit");
btn.onclick = function (){
	var name = document.getElementById("name").value;
    var age = document.getElementById("age").value;
    $.post("/main/submit",{name:name, age:age});
    alert("修改成功！");
}
</script>

控制器代码
function submit(){
	    $params = $this->request->data;
	    if($this->request->is('post')){
	    	$data["data"]["name"] = $params['name'];
			$data["data"]["age"] = $params['age'];
			$json_strings = json_encode($data);
			file_put_contents("1.json",$json_strings);
	    }    
}